package com.bocai.controller;

import com.bocai.bean.CustomEvent;
import com.bocai.service.ICustomEventService;
import com.bocai.utils.CodeEnum;
import com.bocai.utils.ObjUtils;
import com.bocai.utils.ResponseData;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("customEvent")
public class CustomEventConttoller {

    @Autowired
    private ICustomEventService customEventService;


    @ApiOperation(value = "查询热门禁用比赛", notes = "查询热门禁用比赛列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "isEnable", required = false, dataType = "int", value = "是否禁用（0不禁用1禁用）", defaultValue = "0"),
            @ApiImplicitParam(paramType = "query", name = "isHot", required = false, dataType = "int", value = "是否热门（0不热门 1热门）", defaultValue = "0"),
    })
    @RequestMapping(value = "/getHotEvents", method = RequestMethod.GET)
    @ResponseBody
    public ResponseData getHotEvents(Integer isEnable, Integer isHot) {
        ResponseData data = new ResponseData();
        CustomEvent customEvent = new CustomEvent();
        if (isEnable != null)
            customEvent.setIsEnable(isEnable);
        if (isHot != null)
            customEvent.setIsHot(isHot);
        data.setResults(customEventService.selectEvents(customEvent));
        return data;
    }

    @ApiOperation(value = "查询自定义比赛详情", notes = "查询自定义比赛")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "eventId", required = false, dataType = "int", defaultValue = "0"),
    })
    @RequestMapping(value = "/getCustomEvents", method = RequestMethod.GET)
    @ResponseBody
    public ResponseData getHotEvents(Integer eventId) {
        ResponseData data = new ResponseData();

        CodeEnum codeEnum = ObjUtils.validateParams(new Object[]{eventId});
        if (ObjUtils.isNotEmpty(codeEnum)) {
            data.setCodeEnum(CodeEnum.CODE_90002);
            return data;
        }

        data.setCodeEnum(CodeEnum.SUCCESS);

        data.setResults(customEventService.selectEvent(eventId));
        return data;
    }
}
